<?php

// src/Sdz/UserBundle/Entity/User.php
/**
 * @author Gaël Francillette 
 * 
 */

namespace ProjetA\UserBundle\Entity;

use FOS\UserBundle\Entity\User as BaseUser;
use ProjetA\GroupeBundle\Entity\Groupe as Groupe;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="user")
 */
class User extends BaseUser {

    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;
    /**
     * @ORM\Column(name="sexe", type="string", length=1)
  */
    protected $sexe;
    /**
     * @ORM\Column(name="age", type="integer")
  */
    protected $age;
    /**
     * @ORM\Column(name="ville", type="string", length=255)
  */
    protected $ville;
    /**
     * @ORM\Column(name="codep", type="string", length=5)
  */
    protected $codeP;
    /**
     * @ORM\Column(name="nom", type="string", length=255)
  */
    protected $nom;
    /**
     * @ORM\Column(name="prenom", type="string", length=255)
  */
    protected $prenom;
    // Relation entre groupe et users

    /**
     * Bidirectional Proprio
     *
     * @ORM\ManyToMany(targetEntity="ProjetA\GroupeBundle\Entity\Groupe", inversedBy="demandeurs")
     * @ORM\JoinTable(name="user_demande_groupe",
     *   joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
     *   inverseJoinColumns={@ORM\JoinColumn(name="groupe_demande_id", referencedColumnName="id")}
     * )
     */
    private $demandes;

    /**
     * Bidirectional Proprio
     *
     * @ORM\ManyToMany(targetEntity="ProjetA\GroupeBundle\Entity\Groupe", inversedBy="inscrits")
     * @ORM\JoinTable(name="user_inscrit_groupe",
     *   joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
     *   inverseJoinColumns={@ORM\JoinColumn(name="groupe_inscrit_id", referencedColumnName="id")}
     * )
     */
    private $inscriptions;

    /**
     * Bidirectional - One-To-Many Fils
     *
     * @ORM\OneToMany(targetEntity="ProjetA\GroupeBundle\Entity\Groupe", mappedBy="moderateur")
     */
    private $groupes;

    // Fin relation Groupe Users

    /**
     * Bidirectional - One-To-Many 
     *
     * @ORM\OneToMany(targetEntity="ProjetA\GroupeBundle\Entity\Post", mappedBy="user")
     */
    private $posts;

    public function getDemandes() {
        return $this->demandes->toArray();
    }

    public function getInscriptions() {
        return $this->inscriptions->toArray();
    }

    public function getGroupes() {
        return $this->groupes->toArray();
    }

    public function getPosts() {
        return $this->posts->toArray();
    }
    public function addPost($post){
        $this->posts->add($post);
    }

    public function addInscritGroupe(Groupe $groupe) {
        $this->inscriptions->add($groupe);
        $groupe->addInscrit($this);
    }
    public function suppInscritGroupe(Groupe $groupe){
        $this->inscriptions->removeElement($groupe);
        $groupe->suppInscrit($this);
    }

    public function addDemandeGroupe(Groupe $groupe) {
        $this->demandes->add($groupe);
        $groupe->addDemande($this);
    }
   public function suppDemandeGroupe(Groupe $groupe) {
        $this->demandes->removeElement($groupe);
        $groupe->suppDemande($this);
    }

    public function estModerateurDe(Groupe $groupe) {
        $this->groupes->add($groupe);
        $groupe->setModerateur($this);
    }
    public function __construct(){
        parent::__construct();
        $this->sexe = "f";
        $this->ville = "";
        $this->codeP = "";
        $this->nom = "";
        $this->prenom = "";
        $this->age = 1;
        $this->demandes = new \Doctrine\Common\Collections\ArrayCollection();
        $this->inscriptions = new \Doctrine\Common\Collections\ArrayCollection();
        $this->groupes = new \Doctrine\Common\Collections\ArrayCollection();
        $this->posts = new \Doctrine\Common\Collections\ArrayCollection();
    }
    
    /**
     * Set sexe
     *
     * @param string $sexe
     */
    public function setSexe($sexe)
    {
        $this->sexe = $sexe;
    }

    /**
     * Get sexe
     *
     * @return string 
     */
    public function getSexe()
    {
        return $this->sexe;
    }

    /**
     * Set age
     *
     * @param integer $age
     */
    public function setAge($age)
    {
        $this->age = $age;
    }

    /**
     * Get age
     *
     * @return integer 
     */
    public function getAge()
    {
        return $this->age;
    }

    /**
     * Set ville
     *
     * @param string $ville
     */
    public function setVille($ville)
    {
        $this->ville = $ville;
    }

    /**
     * Get ville
     *
     * @return string 
     */
    public function getVille()
    {
        return $this->ville;
    }

    /**
     * Set codeP
     *
     * @param string $codeP
     */
    public function setCodeP($codeP)
    {
        $this->codeP = $codeP;
    }

    /**
     * Get codeP
     *
     * @return string 
     */
    public function getCodeP()
    {
        return $this->codeP;
    }

    /**
     * Set nom
     *
     * @param string $nom
     */
    public function setNom($nom)
    {
        $this->nom = $nom;
    }

    /**
     * Get nom
     *
     * @return string 
     */
    public function getNom()
    {
        return $this->nom;
    }

    /**
     * Set prenom
     *
     * @param string $prenom
     */
    public function setPrenom($prenom)
    {
        $this->prenom = $prenom;
    }

    /**
     * Get prenom
     *
     * @return string 
     */
    public function getPrenom()
    {
        return $this->prenom;
    }
}

?>
